// 防抖函数，合并版本，immediate为true时为立即执行
export function debounce(func: Function, wait: number, immediate: boolean) {
  let timeout;
  return function (...args) {
    const context = this as any;
    // const args: any = [...arguments];
    if (timeout) clearTimeout(timeout);
    if (immediate) {
      const callNow = !timeout;
      timeout = setTimeout(() => {
        timeout = null;
      }, wait);
      if (callNow) func.apply(context, args);
    } else {
      timeout = setTimeout(() => {
        func.apply(context, args);
      }, wait);
    }
  };
}
